#ifndef SAFEMAP_H_
#define SAFEMAP_H_

#include <map>

#include "Common\stragy\threadsafe\CriticalLock.h"

namespace FURY
{
	namespace CONTAINER
	{
		using FURY::STRAGY::CriticalLock;

		template<typename K, typename T>
		class SafeMap
		{
			typedef std::map<K, T>	MapContainer;
			MapContainer	m_container;
			CriticalLock	m_lock;
		public:
			SafeMap(void) {};
		public:
			~SafeMap(void) {};

			void Insert(K key, T obj)
			{
				m_container.insert(std::make_pair(key, obj));
			};

			bool Has(K key)
			{
				if (m_container.find(key) == m_container.end())
					return false;
				else
					return true;
			};

			T& operator[](K key)
			{
				return m_container[key];
			};

			bool Erase(K key)
			{
				MapContainer::iterator iter = m_container.find(key);
				if (iter == m_container.end())
					return false;
				else
				{
					m_container.erase(iter);
					return true;
				}
			};

			void Clear(void)
			{
				m_container.clear();
			};

			bool Empty(void)
			{
				return m_container.empty();
			};

			operator CriticalLock&()
			{
				return m_lock;
			};
		};
	};
};

#endif	//	SAFEMAP_H_